﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Blog.TemplateEngine
{
    public class Template
    {
        NodeList mNodes;

        internal Template(string source, Engine engine)
        {
            mNodes = Compile(source, engine);
        }

        private NodeList Compile(string source, Engine engine)
        {
            var lexer = new Lexer(source);
            var parser = new Parser(lexer.Tokenize(), engine);
            return parser.Parse();
        }

        public string Render()
        {
            return Render(new Context());
        }

        public string Render(Context context)
        {
            return mNodes.Render(context);
        }
    }
}
